package com.tourism.core.cn.result;
/*********************************************************************
 Copyright(c) 2024 All Rights Reserved .
 Author : liliang
 CreatedOn : 2024/12/26 22:41
 Email : 2061996582@qq.com
 Describe : TODO
 UseCase :
 Version : 2024|V1.0.0.0
 **********************************************************************/

import com.tourism.core.cn.enums.ResultCodeEnum;
import lombok.Data;

/**
 * @author new
 * @date 2024/12/26 22:41
 */
@Data
public class Result <T>{
    private Integer code;
    private String message;
    private T data;

    public static <T> Result<T> success(T data) {
        Result<T> result = new Result<>();
        result.setCode(ResultCodeEnum.SUCCESS.getCode());
        result.setMessage(ResultCodeEnum.SUCCESS.getMessage());
        result.setData(data);
        return result;
    }

    public static <T> Result<T> error(ResultCodeEnum resultCode) {
        Result<T> result = new Result<>();
        result.setCode(resultCode.getCode());
        result.setMessage(resultCode.getMessage());
        return result;
    }

    public static <T> Result<T> error(ResultCodeEnum resultCode, String message) {
        Result<T> result = new Result<>();
        result.setCode(resultCode.getCode());
        result.setMessage(message);
        return result;
    }
}
